/*
Esta clase se usa para marcar la localizacion exacta de un recurso. La primera variable es el path. La segunda sirve para especificar
que el recurso esta contenido dentro de un fichero (por ejemplo si buscamos una clave especifica en un fichero json.
*/
#ifndef _Z3D_RESOURCE_LOCATOR_H_
#define _Z3D_RESOURCE_LOCATOR_H_

#include "resourceType.h"
#include "Log/LogSystem.h"
#include <string>

namespace z3d{
	namespace utils{
		class ResourceLocator{
		private:
			std::string _pathLocation;
			std::string _specificLocation;
			ResourceType _resType;
			std::string _protocol;
			std::string _host;
			std::string _port;
			std::string _path;
                        std::string _user;
                        std::string _password;
		
                        glog::CGlobalLog& _log;
                        /**
                         * Extract the protocol from the path and returns the remaining chunk to process
                         * @param path that contains the unprocessed path
                         * @return the new unprocessed path
                         */
                        std::string extractProtocol(const std::string& path);
                        /**
                         * Extracts the user name and password of the given path
                         * @param path path that contains the unprocessed path
                         * @return the new unprocessed path
                         */
                        std::string extractUserAndPassword(const std::string& path);
                        
                        /**
                         * Extracts the host and password (if any)
                         * @param path The path to extract
                         * @return the new unprocessed path
                         */
                        std::string extractHostAndPort(const std::string& path);
                        
                        /**
                         * Extracts the path
                         * @param path
                         * @return 
                         */
                        std::string extractPath(const std::string& path);
                        
		public:
			/// Constructor
			ResourceLocator(const std::string& pathLocation, const std::string& specificLocation, const ResourceType& resType)
				:_pathLocation(pathLocation)
				,_specificLocation(specificLocation)
				,_resType(resType)
                                ,_log(glog::CGlobalLog::getSingleton())
				{}
                        /**
                        * Separa el path location en protocolo, host y path, siempre que sea posible.
                        */  
                        void init();
			const std::string& getPathLocation() const{
				return _pathLocation;
			}

			const std::string& getSpecificLocation() const{
				return _specificLocation;
			}
			const ResourceType& getResourceType() const {
				return _resType;
			}
                        /**
                         * Return the protocol if is set
                         * @return the protocol
                         */
                        const std::string getProtocol() const;
                        /**
                         * Return the user name
                         * @return the user name
                         */
                        const std::string getUserName() const;
                        /**
                         * Return the password
                         * @return the password
                         */
                        const std::string getPassword() const;
                        /**
                         * Return the host
                         * @return the host
                         */
                        const std::string getHost() const;
                        /**
                         * Return the port
                         * @return the port
                         */
                        const std::string getPort() const;
                        /**
                         * Return the path
                         * @return the path
                         */
                        const std::string getPath() const;
		};
	}
}

#endif //_Z3D_RESOURCE_LOCATOR_H_
